<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">{{data.title}}</block>
		</cu-custom>
		<view>
			<view class="content-nav nav padding-xs bg-white">
				<view class="cu-item" :class="currview==1?'cur':''" @click="viewSection(1,1)">作品</view>
				<view class="cu-item" :class="currview==2?'cur':''" @click="viewSection(1,2)">日记</view>
				<view class="cu-item" @click="naviTo('lector/lesson')">课程</view>
				<view class="cu-item" @click="naviTo('lector/special')">专栏</view>
			</view>
			<view class="text-empty text-center" v-if="data.releases.length==0">
				<text class="text-gray">空空如也</text>
			</view>
			<view class="records" v-else>
				<view class="cu-card article">
					<view class="cu-item shadow" v-for="(item, index) in data.releases" :key="index">
						<view class="content">
							<image  @click="naviTo('diary/detail',{id:item.id})" :src="item.cover" mode="aspectFill"></image>
							<view class="desc">
								<view  @click="naviTo('diary/detail',{id:item.id})" class="title">
									<view>
										<text>{{item.title || item.worksTime+'日记'}}</text>
										<text class="cu-tag round bg-orange sm margin-left-xs" v-if="item.audit==0">待审核</text>
									</view>
								</view>
								<view  @click="naviTo('diary/detail',{id:item.id})" class="text-content">{{item.content}}</view>
								<view>
									<view @click="doRemove(item.id,index)" class="cu-btn bg-red sm radius">删除</view>
									<view @click="naviTo('index/post',{id:item.id})" class="cu-btn bg-blue sm radius margin-left">编辑</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="text-center padding-top-sm bg-white" v-if="loadmore=='more'">
					<view class="loadmore">
						<image src="@/static/images/img_home_showmore.png" class="png"></image>
					</view>
				</view>
				<uni-load-more class="bg-white" :status="loadmore" :contentText="contentText"></uni-load-more>
			</view>
		</view>
	</view>
</template>

<script>
	import core from "@/static/core.js"
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
	
	export default {
		components: {uniLoadMore},
		data() {
			return {
				currview:'works',
				page:1,
				loadmore:'more',
				contentText:{
					"contentdown":"加载更多数据",
					"contentrefresh":"加载中...",
					"contentnomore":"我是有底线的~"
				},
				data:{
					title:"我的发布",
					releases:[],
					nickname:""
				}
			}
		},
		onLoad() {
			if(core.userinfo.uid<=0) return core.toast('请先登录sd','login');
		},
		onShow() {
			var that = this;
			this.initData('member/release',{op:this.currview},function(res){
				that.page = 1;
				that.loadmore = res.releases.length<15 ? 'noMore' : 'more';
			});
		},
		onReachBottom() {
			if(this.loadmore!='more') return false;
			this.viewSection(this.page+1,this.currview);
		},
		methods:{
			async initData(route, data={}, callback=false){
				this.viewSection(1,1);
				var that=this;
				that.data.nickname=core.userinfo.nickname;
				// core.get(route,function(res){
				// 	// if(typeof(res.message)!='undefined' && typeof(res.type)!='undefined'){
				// 	// 	return core.report(res, true);
				// 	// }
				// 	// that.data = res;
				// 	uni.setNavigationBarTitle({
				// 		title:res.title
				// 	});
				// 	if(callback){
				// 		callback(res);
				// 	}
				// },data);
			},
			naviTo(page,data={}){
				return core.navito(page,data);
			},
			unSupport(){
				return core.toast('敬请期待');
			},
			async delete(id,index){
				
			},
			 doRemove(id,index){
				var that = this;
			       return core.confirm('将清理掉所有评论数据且不可恢复','删除信息',function(){
					  var line=(that.$api.reqGet({
					  	url:"works/delete/"+id
					  }));
					  if(line!=null){
					  	 core.toast("删除成功",'','success')
					  	that.data.releases.splice(index,1);
					  }
					// core.get('diary/remove',function(res){
					// 	if(res.type!='success') return core.report(res);
					// 	core.toast(res.message,'','success')
					// 	that.data.releases.splice(index,1);
					// },{id:id});
				});
			},
			async viewSection(page=1,view){
				var that = this;
				// that.data.releases=[];
				var audit=-1;
				var a=(await this.$api.reqGet({
					url:"works/selWorks/"+core.userinfo.uid+"/"+view+"/0/"+audit
				})).data;
				that.currview = view
				that.loadmore = that.data.releases.length<15 ? 'noMore' : 'more';
				if(page==1){
						that.page = 1;
						that.data.releases = a;
					}else{
						if(a.length==0) return core.toast('没有更多了~');
						that.data.releases = that.data.releases.concat(a)
					}
				if(that.data.releases==null){
					that.data.releases=[]
				}
				console.log(that.data.releases)
				// return core.get('member/release',function(res){
				// 	// if(typeof(res.message)!='undefined' && typeof(res.type)!='undefined') return core.report(res);
				// 	that.currview = view;
				// 	that.loadmore = res.releases.length<15 ? 'noMore' : 'more';
				// 	if(page==1){
				// 		that.page = 1;
				// 		that.data.releases = res.releases;
				// 	}else{
				// 		if(res.releases.length==0) return core.toast('没有更多了~');
				// 		that.data.releases = that.data.releases.concat(res.releases)
				// 	}
				// },{op:view,page:page});
			}
		}
	}
</script>

<style>
</style>
